Ext.namespace('VAS');

VAS.DynamicGridWindow = function($config) {
	var _this = this;
	var $height;

	_this._getHeight = function(_height,_y) {
		if (typeof(_height) !== "undefined") {
			if (typeof(_height)==='string'&&_height.indexOf('%') > -1) {
				$height = document.body.clientHeight -_y-190;			
			} else if(typeof(_height)==='number'){
				$height = _height - 50;
			}
		} 
		
		return $height;

	}
	
	
	
		_this._getWinHeight = function(_height) {
			
		if (typeof(_height) !== "undefined") {
			if (typeof(_height)==='string'&&_height.indexOf('%') > -1) {
				var percent = _height.substring(0, _height.length - 1) / 100;
				$height = document.body.clientHeight * percent ;
			} else if(typeof(_height)==='number'){
				$height = _height;
			}
		} 
		
		return $height;
	}
	
	_this._getWidth = function(_width,_x) {			
		var $width;
		if (typeof(_width) !== "undefined") {
			if (typeof(_width)==='string'&&_width.indexOf('%') > -1) {
			$width = document.body.clientWidth -_x-148;	
			} else if(typeof(_width)==='number'){
				$width = _width;
			}
		} 
		return $width;
	}
	
	_this._getWinWidth = function(_width,_x) {			
		var $width;
		if (typeof(_width) !== "undefined") {
			if (typeof(_width)==='string'&&_width.indexOf('%') > -1) {
				if( typeof(_x) !== 'undefined'){		// 当gridwindow为弹出窗口时，_x可能为undefined
					$width = document.body.clientWidth - _x - 130;	
				}else{
					$width = document.body.clientWidth -130;	
				}
			} else if(typeof(_width)==='number'){
				$width = _width;
			}
		} 
		return $width;
	}
	var grid = new VAS.CellEditorGrid({
		title             : $config.gridPanel.title || "",
		id                : $config.gridPanel.id,
		gridUrl           : $config.gridPanel.url,
		storeUrl          : $config.gridPanel.storeUrl,
		params            : $config.gridPanel.params,
		rowNumberer       : true,
		checkboxSelModel  : true,
		sm                : new Ext.grid.CheckboxSelectionModel({
										defaults : {
											sortable : true											
										}
										}),
		
		autoScroll: 	true,
		autoWidth: true,
		page 			  : $config.gridPanel.page == undefined || typeof($config.gridPanel.page) != "boolean" ? true : $config.gridPanel.page,
		lisenters         : {}
		,gridPanelParams:$config.gridPanelParams
		,height            :  _this._getHeight($config.height,$config.y)
		,width			   : _this._getWidth($config.width,$config.x)
//		,plugins:filters
		,menuid			   : $config.menuid
	});
	
	var thisConfig = {
		closable   : false,
		autoScroll : true,
		items      : grid,
		autoScroll : true
//		,height    : _this._getWinHeight($config.height)
	};
	var _config = $config || {};

	Ext.apply(_this, Ext.apply(thisConfig, _config));
	Ext.apply(_this, {width :_this._getWinWidth($config.width,$config.x)});		//设置宽度
	VAS.DynamicGridWindow.superclass.constructor.call(_this);

};

Ext.extend(VAS.DynamicGridWindow, VAS.BasicWindow, {

});

Ext.reg('dynamicGrid-win', VAS.DynamicGridWindow);
